<?php
class App_Page_Service_Block
{
	/**
	 * @var App_Page_Model_Block
	 */
	protected $_modelBlock;
	
	/**
	 * @return void
	 */
	public function __construct() 
	{
		$this->_modelBlock = Main_Model::factory('Page_Model_Block');	
	}
	
	/**
	 * @var App_Page_Model_Block
	 */
	public function getModelBlock()
	{
		return $this->_modelBlock;
	}
	
	/**
	 * @param array $data
	 * @return bool
	 */
	public function insertItem($data)
	{
		$data['lang_id'] = ($data['lang_id'] == 0) ?  'null' : $data['lang_id'];
		$data['plugin_id'] = ($data['plugin_id'] == 0) ? 'null' : $data['plugin_id'];  
		
		return $this->_modelBlock->insertItem($data);
	}
	
	/**
	 * @param array $data
	 * @param int $blockId
	 * @return bool
	 */
	public function updateItem($data, $blockId)
	{
		$data['lang_id'] = ($data['lang_id'] == 0) ?  'null' : $data['lang_id'];
		$data['plugin_id'] = ($data['plugin_id'] == 0) ? 'null' : $data['plugin_id'];
		
		return $this->_modelBlock->updateItem($data, $blockId);
	}
	
	/**
	 * @param int $id
	 * @return array
	 */
	public function getItemById($id) 
	{
		return $this->_modelBlock->getItemById($id);
	}
	
	/**
	 * @param int $id
	 * @return bool
	 */
	public function deleteItem($id) 
	{
		return $this->_modelBlock->deleteItem($id);
	}
	
	/**	
     * @param string $value 
     * @param array $otherCond
     * @return bool
     */
    public function checkUnique ($value, $otherCond)
    {
    	$pageId = $otherCond['page_id'];
    	$pageId = ($pageId != 0) ? $pageId : null;
    	$langId = Zend_Registry::getInstance()->langId; 
    	
        $list = $this->_modelBlock->getItemByNameAndPageId($value, $pageId, $langId);
        return empty($list) ? true : false;
    }
	
	
}
?>